<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="left-con">
        <div class="input-frame" style="width: 164px">
          <Input type="text" placeholder="请输入姓名" style="width: 164px" v-model="params.name"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" placeholder="请输入联系方式" style="width: 164px" v-model="params.mobile"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Select placeholder="请输入所属部门" style="width: 164px" v-model="params.department">
            <Option value="1">省直机关</Option>
            <Option value="2">驻沈省（中）直企业</Option>
            <Option value="3">驻沈省（部）属高校 </Option>
          </Select>
        </div>
        <Button class="btnClass" type="info" size="small" @click="searchData(1)">搜索</Button>
        <Button class="btnClass" type="success" size="small" @click="addData(1)">添加</Button>
        <Button class="btnClass" type="info" size="small" @click="exportPeopleData()">导入</Button>
        <Button class="btnClass" type="primary" size="small" @click="findPartyMemberNoPageList()">导出</Button>
        <Button class="btnClass" type="error" size="small"><a :href="templateUrl" style="color: white">下载导入模板</a></Button>
        </div>
    </div>
    <Table border :columns="columns" :data="dataList" size="small" ref="table">
        <template slot="sex" slot-scope="{ row, index }">
          <span v-if="row.sex == '0'">男</span>
          <span v-else-if="row.sex == '1'">女</span>
        </template>
        <template slot="department" slot-scope="{ row, index }">
          <span v-if="row.department == '1'">省直机关</span>
          <span v-else-if="row.department == '2'">驻沈省（中）直企业</span>
          <span v-else-if="row.department == '3'">驻沈省（部）属高校</span>
        </template>
        <template slot="action" slot-scope="{ row }">
          <Row style="margin-bottom: 5px; margin-top: 2px">
            <Button class="table-action-btn" style="margin-right: 5px" type="success" size="small" @click="show(row, true)">编辑</Button>
            <Button class="table-action-btn" type="error" size="small" @click="deletePeople(row)">删除</Button>
          </Row>
        </template>
      </Table>
    <Row type="flex" justify="end" class="page_style">
      <Page :current="params.pageNo" :total="params.totalRecord" show-sizer :page-size="params.pageSize" show-elevator
            @on-change="pageAction" @on-page-size-change="pageSizeChange"/>
    </Row>
    <Drawer title="党员信息" v-model="drawer1" width="720">
      <Form :model="formData">
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="姓名" label-position="top">
              <Input v-model="formData.name" placeholder="请填写姓名" />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="性别" label-position="top">
              <RadioGroup v-model="formData.sex">
                <Radio label="0">男</Radio>
                <Radio label="1">女</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="生日" label-position="top">
              <DatePicker type="date" placeholder="请选择生日" v-model="formData.birthday" style="width: 100%;"></DatePicker>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="手机号码" label-position="top">
              <Input v-model="formData.mobile" placeholder="请填写手机号码" />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="部门" label-position="top">
              <Select v-model="formData.department">
                <Option value="1">省直机关</Option>
                <Option value="2">驻沈省（中）直企业</Option>
                <Option value="3">驻沈省（部）属高校</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="单位" label-position="top">
              <Input v-model="formData.company" placeholder="请填写单位" />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="职务" label-position="top">
              <Input v-model="formData.duty" placeholder="请填写职务" />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="报到时间" label-position="top">
              <DatePicker type="date" placeholder="请选择报到时间" v-model="formData.checkin_time" style="width: 100%;"></DatePicker>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="特长" label-position="top">
              <Input v-model="formData.strongpoint" placeholder="请填写特长" />
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div class="demo-drawer-footer">
        <Button style="margin-right: 8px" @click="drawer1 = false">取消</Button>
        <Button type="primary" @click="complete()">确定</Button>
      </div>
    </Drawer>
    <Modal
        v-model="importModal"
        title="导入信息">
      <div>
        <Tag color="error" size="medium">提示：一次不要导入过多数据</Tag>
      </div>
      <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importExcel">导入驻沈党员信息</Button>
    </Modal>
    <div v-if="importModalExcel">
      <Modal
          v-model="importModalExcel"
          width="1800"
          title="导入网格人员数据">
        <dispose-excel :columns="exportColumnsExcel" :url="exportUrlExcel" :failedUrl="exportFailedUrlExcel"></dispose-excel>
      </Modal>
    </div>
  </div>
</template>

<script>
import { createPartyMember, updatePartyMember, getPartyMemberList } from '@/api/grid'
import { date2str } from '@/api/eventlist'
import { deletePartyMemberID, findPartyMemberNoPageList } from '../../../../api/eventlist'
import DisposeExcel from '../../dispose-excel/dispose-excel'
export default {
  name: 'party-member-list',
  components: { DisposeExcel },
  data () {
    return {
      importModal: false,
      importModalExcel: false,
      exportColumnsExcel: [
        {
          align: 'center',
          title: '姓名',
          key: 'name'
        },
        {
          align: 'center',
          title: '性别',
          key: 'sex'
        },
        {
          align: 'center',
          title: '出生日期',
          key: 'birthday'
        },
        {
          align: 'center',
          title: '手机号码',
          key: 'mobile'
        },
        {
          align: 'center',
          title: '所属部门',
          key: 'department'
        },
        {
          align: 'center',
          title: '单位',
          key: 'company'
        },
        {
          align: 'center',
          title: '职务',
          key: 'duty'
        },
        {
          align: 'center',
          title: '报到时间',
          key: 'checkin_time'
        },
        {
          align: 'center',
          title: '特长',
          key: 'strongpoint'
        }
      ],
      exportUrlExcel: '/api/ac/grid/partyMemberService/savePartyMember',
      exportFailedUrlExcel: '',
      columns: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          width: '60'
        },
        {
          title: '姓名',
          key: 'name',
          align: 'center'
        },
        {
          title: '联系电话',
          key: 'mobile',
          align: 'center'
        },
        {
          title: '性别',
          slot: 'sex',
          align: 'center'
        },
        {
          title: '出生日期',
          key: 'birthday',
          align: 'center'
        },
        {
          title: '所属部门',
          slot: 'department',
          width: '200',
          align: 'center'
        },
        {
          title: '职务',
          key: 'duty',
          align: 'center'
        },
        {
          title: '报道时间',
          key: 'checkin_time',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'action',
          width: '250',
          align: 'center'
        }
      ],
      exportColumns: [
        {
          title: '姓名',
          key: 'name',
          align: 'center'
        },
        {
          title: '联系电话',
          key: 'mobile',
          align: 'center'
        },
        {
          title: '性别',
          key: 'sex',
          align: 'center'
        },
        {
          title: '出生日期',
          key: 'birthday',
          align: 'center'
        },
        {
          title: '所属部门',
          key: 'department',
          align: 'center'
        },
        {
          title: '单位',
          key: 'company',
          align: 'center'
        },
        {
          title: '职务',
          key: 'duty',
          align: 'center'
        },
        {
          title: '报道时间',
          key: 'checkin_time',
          align: 'center'
        },
        {
          title: '区',
          key: 'area',
          align: 'center'
        },
        {
          title: '街道',
          key: 'street',
          align: 'center'
        },
        {
          title: '社区',
          key: 'community',
          align: 'center'
        }
      ],
      dataList: [],
      formData: {},
      drawer1: false,
      params: {
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0
      },
      addFlag: true,
      big_type_dict: '',
      severUserInfo: {},
      templateUrl: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/grid/驻沈省（中）直机关及企事业单位在职党员导入模板v2_8508686386.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0'
    }
  },
  methods: {
    pageAction (page) {
      this.params.pageNo = page
      this.init()
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.init()
    },
    show (item, flag) {
      this.drawer1 = true
      this.addFlag = flag
      this.formData.name = item.name
      this.formData.sex = item.sex
      this.formData.birthday = item.birthday
      this.formData.mobile = item.mobile
      this.formData.department = item.department
      this.formData.company = item.company
      this.formData.duty = item.duty
      this.formData.strongpoint = item.strongpoint
      this.formData.checkin_time = item.checkin_time
      this.formData.id = item.id
    },
    complete () { // 诉求提报
      let url = ''
      if (this.formData.id) {
        url = updatePartyMember
      } else {
        url = createPartyMember
      }
      this.formData.birthday = date2str(this.formData.birthday)
      this.formData.checkin_time = date2str(this.formData.checkin_time)
      url(this.formData).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({
            title: '成功提示',
            desc: '添加党员信息成功'
          })
          this.drawer1 = false
          this.init()
          return
        }
        this.$Notice.error({
          title: '错误提示',
          desc: res.data.errmsg
        })
      })
    },
    addData () {
      this.addFlag = true
      this.drawer1 = true
      this.formData = {}
    },
    init () { // 列表数据
      getPartyMemberList(this.params).then(res => {
        if (res.data.errcode === 0) {
          this.dataList = res.data.data.results
          this.params.totalRecord = res.data.data.totalRecord
          return
        }
        this.$Notice.error({
          title: '错误提示',
          desc: res.data.errmsg
        })
      })
    },
    searchData () { // 搜索
      this.params.pageNo = 1
      this.init()
    },
    deletePeople (e) {
      let data = {
        id: e.id
      }
      deletePartyMemberID(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({ title: '删除成功！', desc: ret.data.errmsg })
          this.init()
        } else {
          this.$Notice.error({ title: '删除失败！', desc: ret.data.errmsg })
        }
      })
    },
    findPartyMemberNoPageList () {
      findPartyMemberNoPageList().then(ret => {
        if (ret.data.errcode === 0) {
          let data = ret.data.data
          this.$refs.table.exportCsv({
            filename: this.severUserInfo.company_name + '_驻沈党员数据',
            columns: this.exportColumns,
            data: data
          })
        } else {
          this.$Notice.error({ title: '删除失败！', desc: ret.data.errmsg })
        }
      })
    },
    exportPeopleData () {
      this.importModal = true
    },
    importExcel () {
      this.importModalExcel = true
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    this.init()
  }
}
</script>

<style scoped>
  .container{
    padding: 12px;
  }
  .page_style {
    margin: 20px 5px;
  }

  .input-frame {
    width: 120px;
    margin-right: 10px;
    float: left;
  }

  .house-list > .group {
    background: white;
    padding: 10px;
    margin-top: 10px;
  }

  .house-list > .group > .item {
    border-bottom: 1px solid #f5f5f5;
    padding: 10px 0;
  }

  .house-list > .group > .item .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .house-list > .group > .item .title {
    font-size: 14px;
    color: #333333;
  }

  .house-list > .group > .item .address {
    font-size: 12px;
    color: gray;
    display: flex;
    align-items: center;
  }

  .house-list > .group > .item .detail {
    font-size: 12px;
    color: dodgerblue;
  }

  .opt-area-02 {
    display: flex;
    align-items: center;
    flex-direction: column;
    border: 1px solid #abdcff;
    background-color: #f0faff;
    padding: 8px 16px 8px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .opt-area-02 .right-con {
    width: 100%;
    margin-top: 5px;
    display: flex;
  }

  .opt-area-02 .left-con {
    font-size: 14px;
    width: 100%;
  }

  .opt-area-02 .left-con span {
    font-weight: bold;
  }

  .opt-area-02 .right-con input {
    width: 150px;
    margin-right: 10px;
  }

  .opt-area-02 .right-con .input-frame {
    width: 200px;
    margin-right: 10px;
  }

  .table-action-btn {
    margin-bottom: 3px;
  }

  .container >>> .ivu-btn-small {
    height: 24px;
    padding: 0 5px;
    font-size: 12px;
    border-radius: 3px;
  }

  .btn-action {
    margin-bottom: 10px;
  }

  .mp10 {
    margin-right: 10px;
  }
  .title-style {
    color: red;
  }
  .mb20 {
    margin-bottom: 20px;
  }
  .ivu-table-row {
    height: 57px;
  }
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50%  { transform: rotate(180deg);}
    to   { transform: rotate(360deg);}
  }
  .demo-spin-col{
    height: 100px;
    position: relative;
    /*border: 1px solid #eee;*/
  }
  .container>>>.ivu-icon-ios-arrow-forward:before{
    color: black;
  }
  .btnClass{
    margin-top: 5px;
    margin-right:5px
  }
</style>
